@extends('admin.tableLayout')
@section('title','退款订单')
@section('barName','退款订单')
@section('quote')
    <hr/>
    <form class="layui-form">
        <div id="select" class="layui-inline"></div>
        <div class="layui-inline">
            <input type="text" class="layui-input" width="200px" id="datetime" name="searchTime" value="" placeholder="日期范围搜索">
        </div>
        <button lay-filter="export" class="layui-btn" id="export"><i class="fa fa-cloud-down" aria-hidden="true"></i> 导出</button>

    </form>
@endsection
@section('checkbox_btn')
    <script type="text/html" id="member">

        @{{# if(d.member.nickname==undefined){ }}
        <span>未查询</span>
        @{{# }else{ }}
        <span><a href="/admin/member/member/distribute/@{{ d.member.id }}" target="_blank"> @{{ d.member.nickname }}</a></span>
        @{{# } }}
    </script>
    <script type="text/html" id="parent">

        @{{# if(d.parent.nickname===undefined){ }}
        <span>无推广人</span>
        @{{# }else{ }}
        <span><a href="/admin/member/member/distribute/@{{ d.parent.id }}" target="_blank"> @{{ d.parent.nickname}}</a></span>
        @{{# } }}
    </script>
    <script type="text/html" id="is_exchange">
    @{{# if(d.is_exchange==1){ }}
    <span>已发放</span>
    @{{# }else{ }}
    <span>未发放</span>
    @{{# } }}
    </script>
@endsection

@section('tableRender')
    <script>
        layui.use(['table','jquery','form'], function(){
            var table = layui.table;
            var $=layui.jquery;
            var form=layui.form;
            var render=table.render({
                elem:"#table",
                page:true,
                id:'idTest',
                url:'{{route('admin.refundOrder_ajaxList')}}',
                where:{searchKey:$("input[name='searchKey']").val()
                },
                height:400,
                cols:  [[ //标题栏
                    {checkbox:true,fixed:true},
                    {field: 'id', title: 'ID', width: 80},
                    {field: 'combo_name', title: '套餐名称', width: 200},
                    {field: 'member', title: '用户', templet:"#member",width: 200},
                    {field: 'member', title: '推广人', templet:"#parent",width: 200},
                    {field: 'refund_money', title: '退还金额', width: 200},
                    {field: 'created_at', title: '发放时间', width: 200},
                    //这里的toolbar值是模板元素的选择器
                ]],
                response: {//返回格式自定义
                    statusName: 'code' //数据状态的字段名称，默认：code
                    ,statusCode: 0 //成功的状态码，默认：0
                    ,msgName: 'msg' //状态信息的字段名称，默认：msg
                    ,countName: 'total' //数据总数的字段名称，默认：count
                    ,dataName: 'data' //数据列表的字段名称，默认：data
                }
            });
            table.on('checkbox(table)', function(obj){
                console.log(obj)
            });
            //上方
            var   active = {
                getCheckData: function(){ //获取选中数据
                    var checkStatus = table.checkStatus('idTest')
                        ,data = checkStatus.data;
                    var str=[];
                    if(data==''){
                        layer.msg('请选中所删除的行',{icon:5})
                        return false;
                    }
                    for(var i=0;i<data.length;i++){
                        str.push(data[i].id);
                    }
                    layer.confirm('是否删除所选',function(index) {
                        $.get('/admin/prize/del', {id: str}, function (obj) {
                            if (obj.info == 'success') {
                                layer.msg('删除成功', {icon: 1});
                                render.reload();
                            } else {
                                layer.msg(obj.msg, {icon: 5});
                            }

                        })
                    })

                },

            };
            $('#export').on('click',function () {
                window.open('{{route('refund.report')}}'+'?searchTime='+$("input[name='searchTime']").val());
                return false;
            })
            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            table.on('tool(table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                if(layEvent === 'detail'){ //查看

                } else if(layEvent === 'del'){ //删除
                    layer.confirm('真的删除行么', function(index){
                        layer.close(index);
                        //向服务端发送删除指令
                        $.get('/admin/prize/del',{id:data.id},function(obj1){
                            if(obj1.info=='success'){
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存

                                layer.msg('删除成功',{icon:1});
                            }else{
                                layer.msg(obj1.msg);
                            }
                        });
                    });
                } else if(layEvent === 'edit'){ //编辑
                    //do something
                    //同步更新缓存对应的值
                    location.href="/admin/prize/"+data.id+"/edit";
                } else if(layEvent==='give'){//授予权限
                    location.href="/admin/role/"+data.id+"/permission";
                }
            });
        });
    </script>
@endsection

